package com.android.nodejs.livejs.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.android.nodejs.livejs.R;
import com.android.nodejs.livejs.models.User;

public class FriendAdapter extends ArrayAdapter<User> {
    
    private List<User> users;
    
	public FriendAdapter(Context context, List<User> users) {
		super(context, R.layout.fragment_friend_item, users);
		this.users = users;
	}
	
	public List<User> getListUsers() {
	    return this.users;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		final ViewHolder holder;
		if (row == null) {
			row = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_friend_item, null);
			holder = new ViewHolder();
			//holder.avatar = (ImageView) row.findViewById(R.id.imgAvatar);
			holder.tvName = (TextView) row.findViewById(R.id.tvName);
			holder.tvLastStatus = (TextView) row.findViewById(R.id.tvLastStatus);
			holder.tvStatus = (TextView) row.findViewById(R.id.tvStatus);
			row.setTag(holder);
		} else {
			holder = (ViewHolder) row.getTag();
		}
		User user = getItem(position);
		holder.tvName.setText(user.getFullName());
		holder.tvLastStatus.setText(user.getLastStatus());
		holder.tvStatus.setText(user.getStatus());
		return row;
	}

	private class ViewHolder {
		//ImageView avatar;
		TextView tvName, tvLastStatus, tvStatus;
	}

}
